package com.easy.order.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.Orders;
import com.easy.common.service.IOrderService;
import com.easy.order.mapper.OrderMapper;

import java.util.List;

public class FlashOrderServiceImpl extends ServiceImpl<OrderMapper, Orders> implements IOrderService {
    @Override
    public Orders getOrderById(Integer id) {
        return super.getById(id);
    }

    @Override
    public int addOrder(Orders order) {
        if (super.save( order)){
            return 1;
        }
        return 0;
    }

    @Override
    public int updateOrder(Orders order) {
       return super.updateById(order)?1:0;
    }

    @Override
    public int deleteOrder(Integer id) {
       return super.removeById(id)?1:0;
    }

    @Override
    public int reverseStatus(Integer id) {
        Orders order = super.getById(id);
        if (order!=null){
            order.setStatus(order.getStatus()==1?0:1);
        }
        if (super.updateById(order)){
            return 1;
        }
        return 0;
    }

    @Override
    public List<Orders> getAll(Orders order) {
        return List.of( );

    }

    @Override
    public IPage<Orders> getPage(Orders order, IPage page) {
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Orders::getOrder_no,order.getOrder_no());
        return super.page(page,queryWrapper);

    }
}
